package com.wuliu.controller;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.utils.DateUtils;
import com.wuliu.common.utils.SecurityUtils;
import com.wuliu.common.utils.StringUtils;
import com.wuliu.common.utils.ThreadLocalContext;
import com.wuliu.common.core.domain.entity.SysAppletUser;
import com.wuliu.system.domain.BasQrcode;
import com.wuliu.system.mapper.BasQrcodeMapper;
import com.wuliu.system.service.ISysAppletUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author realue
 * @version 1.0
 * @date 2023-10-26 9:25
 */
@RestController
@RequestMapping("/app/user")
@Api(tags = {"用户控制器"})
public class SysUserController {
    @Resource
    private ISysAppletUserService sysAppletUserService;

    @PostMapping("/resetPwd")
    @ApiImplicitParam(name = "password", value = "新密码", required = true, dataType = "string", paramType = "query")
    @ApiOperation(value = "重置密码", notes = "")
    public ApiResult<Integer> resetPwd(String password) {
        if (StringUtils.isEmpty(password)) {
            return ApiResult.error("密码不能为空");
        }
        SysAppletUser user = SecurityUtils.getAppletUser();
        SysAppletUser upUser = new SysAppletUser();
        upUser.setUserId(user.getUserId());
        upUser.setPassword(SecurityUtils.encryptPassword(password));
        upUser.setUpdateBy(user.getUserName());
        upUser.setUpdateTime(DateUtils.getNowDate());
        return ApiResult.success(sysAppletUserService.updateSysAppletUser(upUser));
    }

    @GetMapping("/getUserQrCode")
    @ApiOperation(value = "获取业务员下单二维码")
    public ApiResult<String> getUserQrCode(){
        return ApiResult.success(sysAppletUserService.getUserQrCode(1));
    }
}
